v <template>
    <div>
        <el-card class="card">
            <div class="title">
                <h2 style="text-align: center">目标任务查看</h2>
            </div>
        </el-card>
        <br />
        <el-container>
            <el-aside width="400px" style="height: 100vh">
                <el-card>
                    <!--年度查询-->
                    <el-select v-model="value" filterable @change="searchWorkOfTargetYear">
                        <el-option
                            v-for="yearTargetOption in yearTargetOptions"
                            :key="yearTargetOption.value"
                            :label="yearTargetOption.label"
                            :value="yearTargetOption.value"
                        >
                        </el-option>
                    </el-select>

                    <div style="margin-top: 10px">
                        <el-select v-model="departmentValue" filterable style="width: 100px" @change="getDepartmentLabel">
                            <el-option v-for="item in departmentOptions" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                        <!-- <el-button type="primary" style="float: right">查看</el-button> -->
                    </div>
                </el-card>

                <el-menu>
                    <el-menu-item index="1" @click="clickA">
                        <i class="el-icon-menu"></i>
                        <span slot="title">{{ label }} A类</span>
                    </el-menu-item>

                    <div class="menu-buttom" v-show="sideA">
                        <!-- <el-tree :data="taskDataA" :props="defaultProps" @node-click="handleNodeClick"></el-tree> -->
                        <div class="menu-buttom">
                            <div v-for="(content, i) in taskDataA" :key="i" class="el-tree-style">
                                <div>
                                    <!--任务名称-->
                                    <i :class="content.isShow ? 'el-icon-caret-bottom' : 'el-icon-caret-right'"></i>
                                    <span class="el-tree-node__label menu-click" @click="clickNodeA(i)">{{ content.name }}</span>
                                    <div v-if="content.isShow">
                                        <div style="margin-bottom: 10px">
                                            <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                            <!--任务接受部门-->
                                            <span class="el-tree-node__label menu-click" @click="TaskInfoShow(i, 'A')">
                                                &ensp;&ensp;<span v-if="content.acceptDeptId == departmentLabel" style="color: red">
                                                    {{ content.acceptDeptId }}
                                                </span>
                                                <span v-else>
                                                    {{ content.acceptDeptId }}
                                                </span>
                                            </span>
                                            <el-tag v-if="content.level == 0" style="position: absolute; right: 5px">一级</el-tag>
                                            <el-tag type="success" v-if="content.level == 1" style="position: absolute; right: 5px">二级</el-tag>
                                            <el-tag type="warning" v-if="content.level == 2" style="position: absolute; right: 5px">三级</el-tag>
                                        </div>
                                        <div style="margin-top: 5px" v-for="(content2, j) in content.children" :key="j">
                                            <!--二级部门-->
                                            <div style="margin-bottom: 10px">
                                                <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                                &ensp;&ensp;&ensp;&ensp;<span
                                                    class="el-tree-node__label menu-click"
                                                    @click="TaskInfoShowLevel2(i, j, 'A')"
                                                >
                                                    <span v-if="test(content2.acceptDeptId)" style="color: red">
                                                        {{ content2.acceptDeptId }}
                                                    </span>
                                                    <span v-else>
                                                        {{ content2.acceptDeptId }}
                                                    </span>
                                                </span>
                                                <el-tag v-if="content2.level == 0" style="position: absolute; right: 5px">一级</el-tag>
                                                <el-tag type="success" v-if="content2.level == 1" style="position: absolute; right: 5px">二级</el-tag>
                                                <el-tag type="warning" v-if="content2.level == 2" style="position: absolute; right: 5px">三级</el-tag>
                                            </div>
                                            <div
                                                style="margin-top: 5px; margin-bottom: 10px"
                                                v-for="(content3, n) in content2.children"
                                                :key="n"
                                            >
                                                <!--三级部门-->
                                                <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                                &ensp;&ensp;&ensp;&ensp;&ensp;&ensp;<span
                                                    class="el-tree-node__label menu-click"
                                                    @click="TaskInfoShowA3(i, j, n, 'A')"
                                                >
                                                    <span v-if="content3.acceptDeptId == departmentLabel" style="color: red">
                                                        {{ content3.acceptDeptId }}
                                                    </span>
                                                    <span v-else>
                                                        {{ content3.acceptDeptId }}
                                                    </span>
                                                </span>
                                                <el-tag v-if="content3.level == 0" style="position: absolute; right: 5px">一级</el-tag>
                                                <el-tag type="success" v-if="content3.level == 1" style="position: absolute; right: 5px">二级</el-tag>
                                                <el-tag type="warning" v-if="content3.level == 2" style="position: absolute; right: 5px">三级</el-tag>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <br />
                            </div>
                        </div>
                    </div>
                    <el-menu-item index="2" @click="clickB">
                        <i class="el-icon-menu"></i>
                        <span slot="title">{{ label }} B类</span>
                    </el-menu-item>
                    <div class="menu-buttom" v-show="sideB">
                        <!-- <el-tree :data="taskDataA" :props="defaultProps" @node-click="handleNodeClick"></el-tree> -->
                        <div class="menu-buttom">
                            <div v-for="(content, i) in taskDataB" :key="i" class="el-tree-style">
                                <div>
                                    <!--任务名称-->
                                    <i :class="content.isShow ? 'el-icon-caret-bottom' : 'el-icon-caret-right'"></i>
                                    <span class="el-tree-node__label menu-click" @click="showBIssueMethod(i)">
                                        <span v-if="content.allocDeptId == departmentLabel">
                                            <span style="color: red"> 【{{ content.allocDeptId }}】 </span>
                                            {{ content.name }}
                                        </span>
                                        <span v-else>【{{ content.allocDeptId }}】{{ content.name }}</span>
                                    </span>
                                    <div v-if="content.isShow">
                                        <div style="margin-bottom: 10px">
                                            <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                            <!--任务接受部门-->
                                            <span class="el-tree-node__label menu-click" @click="TaskInfoShow(i, 'B')">
                                                &ensp;&ensp;<span v-if="content.acceptDeptId == departmentLabel" style="color: red">
                                                    {{ content.acceptDeptId }}
                                                </span>
                                                <span v-else>
                                                    {{ content.acceptDeptId }}
                                                </span>
                                            </span>
                                            <el-tag v-if="content.level == 0" style="position: absolute; right: 5px">一级</el-tag>
                                            <el-tag type="success" v-if="content.level == 1" style="position: absolute; right: 5px">二级</el-tag>
                                            <el-tag type="warning" v-if="content.level == 2" style="position: absolute; right: 5px">三级</el-tag>
                                        </div>
                                        <div style="margin-top: 5px" v-for="(content2, j) in content.children" :key="j">
                                            <!--二级部门-->
                                            <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                            &ensp;&ensp;&ensp;&ensp;<span class="el-tree-node__label menu-click" @click="TaskInfoShowB3(i, j)">
                                                <span v-if="content2.acceptDeptId == departmentLabel" style="color: red">
                                                    {{ content2.acceptDeptId }}
                                                </span>
                                                <span v-else>
                                                    {{ content2.acceptDeptId }}
                                                </span></span
                                            >
                                            <el-tag v-if="content2.level == 0" style="position: absolute; right: 5px">一级</el-tag>
                                            <el-tag type="success" v-if="content2.level == 1" style="position: absolute; right: 5px">二级</el-tag>
                                            <el-tag type="warning" v-if="content2.level == 2" style="position: absolute; right: 5px">三级</el-tag>
                                            <!-- <div style="margin-top: 5px" v-for="(content3, n) in content2.children" :key="n"> -->
                                            <!--三级部门-->
                                            <!-- <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                                &ensp;&ensp;<span class="el-tree-node__label" >
                                                    <span v-if="content3.acceptDeptId == departmentLabel" style="color: red">
                                                        {{ content3.acceptDeptId }}
                                                    </span>
                                                    <span v-else>
                                                        {{ content3.acceptDeptId }}
                                                    </span></span
                                                >
                                                <el-tag v-if="content3.level == 0">一级</el-tag>
                                                <el-tag type="success" v-if="content3.level == 1">二级</el-tag>
                                                <el-tag type="warning" v-if="content3.level == 2">三级</el-tag>
                                            </div> -->
                                        </div>
                                    </div>
                                </div>
                                <br />
                            </div>
                        </div>
                    </div>
                    <el-menu-item index="3" @click="clickC">
                        <i class="el-icon-menu"></i>
                        <span slot="title">{{ label }} C类</span>
                    </el-menu-item>
                    <div class="menu-buttom" v-show="sideC">
                        <!-- <el-tree :data="taskDataA" :props="defaultProps" @node-click="handleNodeClick"></el-tree> -->
                        <div class="menu-buttom">
                            <div v-for="(content, i) in taskDataC" :key="i" class="el-tree-style">
                                <div>
                                    <div>
                                        <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                        <!--任务接受部门-->
                                        <span class="el-tree-node__label menu-click" @click="TaskInfoShow(i, 'C')">
                                            <!-- {{
                                            content.acceptDeptId
                                        }} -->
                                            <span v-if="content.acceptDeptId == departmentLabel" style="color: red">
                                                {{ content.acceptDeptId }}
                                            </span>
                                            <span v-else>
                                                {{ content.acceptDeptId }}
                                            </span>
                                        </span>
                                        <el-tag v-if="content.level == 0" style="position: absolute; right: 5px">一级</el-tag>
                                        <el-tag type="success" v-if="content.level == 1" style="position: absolute; right: 5px">二级</el-tag>
                                        <el-tag type="warning" v-if="content.level == 2" style="position: absolute; right: 5px">三级</el-tag>
                                    </div>
                                </div>
                                <br />
                            </div>
                        </div>
                    </div>
                </el-menu>
            </el-aside>
            <el-main style="padding-top: 0">
                <el-card v-show="typeOneShow">
                    <el-table :data="taskData" border style="width: 100%">
                        <el-table-column prop="number" label="序号" width="50"> </el-table-column>
                        <el-table-column prop="name" label="任务标题"> </el-table-column>
                        <el-table-column prop="acceptDeptId" label="接受部门" width="200"> </el-table-column>
                        <el-table-column prop="type" label="任务属性" width="70">
                            <template slot-scope="scope">
                                <div v-if="scope.row.type == 0">A</div>
                                <div v-else-if="scope.row.type == 1">B</div>
                                <div v-else-if="scope.row.type == 2">C</div>
                                <div v-else></div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="level" label="分配次级" width="70">
                            <template slot-scope="scope">
                                <div v-if="scope.row.level == 0">一级</div>
                                <div v-else-if="scope.row.level == 1">二级</div>
                                <div v-else-if="scope.row.level == 2">三级</div>
                                <div v-else></div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="isAssess" label="学校年度专项考核" width="120">
                            <template slot-scope="scope">
                                <div v-if="scope.row.isAssess == 0">否</div>
                                <div v-else-if="scope.row.isAssess == 1">是</div>
                                <div v-else></div>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="150">
                            <template slot-scope="scope">
                                <el-button size="mini" type="primary" @click="searchTaskById(scope.row.id)">查看</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-card>
                <!--B类二级点击-->
                <div v-show="tabShowBLevel2">
                    <span style="font-size: 25px"
                        ><strong>{{ label }}B类——{{ departmentNameB }}——{{ taskInfo.name }}</strong></span
                    >
                    <TabView
                        :taskInfos="taskInfo"
                        :targetYear="childYear"
                        :isDept="tabShowBLevel2IsDept"
                        :targetId="childYearId"
                        @refresh="reloadA3"
                    ></TabView>
                </div>
                <!--B类三级-->
                <div v-for="(item, index) in taskDataB3" :key="index" v-show="tabShowBLevel3">
                    <span style="font-size: 25px"
                        ><strong>{{ label }}B类—{{ departmentNameB }}——{{ departmentNameB2 }}——{{ item.name }}</strong></span
                    >
                    <TabView
                        :taskInfos="item"
                        :targetYear="childYear"
                        :isDept="false"
                        :targetId="childYearId"
                        @refresh="reloadA3"
                    ></TabView>
                    <br />
                    <br />
                </div>
                <!--b类下发任务-->

                <div v-show="TabShowIsssue">
                    <span style="font-size: 25px"
                        ><strong>{{ label }}B类——{{ departmentNameB }}</strong></span
                    >
                    <TabBIssue :targetYear="childYear" :targetId="childYearId" ref="TabcRef" :departmentName="departmentNameB"></TabBIssue>
                </div>
                <!--C类-->
                <div v-show="tabShowC">
                    <span style="font-size: 25px"
                        ><strong>{{ label }}C类: {{ departmentNameB }}</strong></span
                    >
                    <TabC :targetYear="childYear" :targetId="childYearId" :departmentIdC="departmentIdC"></TabC>
                </div>

                <!--A类3级-->
                <div v-for="(item, index) in taskInfoArrayA3" :key="index" v-show="tabALast" style="margin-bottom: 20px">
                    <span style="font-size: 25px"
                        ><strong>{{ taskHeader }}——{{ taskHeader2 }}——{{ item.name }}</strong></span
                    >
                    <TabView
                        :taskInfos="item"
                        :targetYear="childYear"
                        :isDept="false"
                        :targetId="childYearId"
                        @refresh="reloadA3"
                    ></TabView>
                </div>
                <div v-show="showSingal">
                    <Tab
                        :taskInfos="taskInfo"
                        :targetYear="childYear"
                        :workInfo_view="workInfo_view"
                        :allocatWork_view="allocatWork_view"
                        :issueWrok_view="issueWrok_view"
                    ></Tab>
                </div>
                <div v-show="showMultiply" v-for="(item, index) in taskInfoArray" :key="index" style="margin-bottom: 20px">
                    <span style="font-size: 25px"
                        ><strong>{{ taskHeader }}——{{ item.name }}</strong></span
                    >
                    <TabViewA2
                        :taskInfos="item"
                        :targetYear="childYear"
                        :isDept="isDept"
                        :targetId="childYearId"
                        @refresh="reloadA3"
                    ></TabViewA2>
                </div>
            </el-main>
        </el-container>
        <el-dialog :visible.sync="level1DialogVisible" width="80%">
            <TabOne
                :taskInfos="taskInfo"
                :targetYear="childYear"
                :workInfo_view="workInfo_view"
                :allocatWork_view="allocatWork_view"
                :issueWrok_view="issueWrok_view"
            ></TabOne>
            <span slot="footer" class="dialog-footer">
                <el-button type="warning" @click="level1DialogVisible = false">关 闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import yearTargetApi from '../../../../api/yearTagetApi';
import workOfYearTargetApi from '../../../../api/workOfYearTargetApi';
import Tab from './TabSingal.vue';
import TabOne from './TabBsearch.vue';
import work from '../../../../api/work';
import TabView from './TabView.vue';
import TabViewA2 from './TabViewA2.vue'
import TabC from './TabC.vue';
import TabBIssue from './TabBIssue.vue';
export default {
    components: {
        Tab,
        TabView,
        TabOne,
        TabC,
        TabBIssue,
        TabViewA2
    },
    data() {
        return {
            loading: false,
            taskDataB3: [],
            // b类三级任务查看
            tabShowBLevel3: false,
            // b类二级判断是否为职能部门
            tabShowBLevel2IsDept: false,
            // b类二级显示
            tabShowBLevel2: false,
            // 只有一种任务的显示
            showSingal: false,
            // 第一种方式是否显示
            typeOneShow: false,
            level1DialogVisible: false,
            taskData: [],
            workInfo_view: true,
            allocatWork_view: true,
            issueWrok_view: true,
            value: '',
            label: '',
            AllTaskDataA: [],
            taskDataA: [],
            AllTaskDataB: [],
            taskDataB: [],
            AllTaskDataC: [],
            taskDataC: [],
            sideA: false,
            sideB: false,
            sideC: false,
            taskInfo: {},
            // 子组件年份
            childYear: '',
            childYearId: '',
            // 部门选项
            departmentOptions: [],
            // 选择部门的值，默认所有，为空
            departmentValue: '',
            departmentLabel: '',

            assignWorkData: [],
            assigntaskDataA: [],
            activeName: 'first',
            data: [],

            yearTargetOptions: [],

            // 点击部门显示,
            clickElse: true,
            //控制显示
            TabViewControl: false,
            taskInfoArray: [],
            taskHeader: '',
            isDept: true,
            // 第二种方式
            showMultiply: false,
            tabALast: false,
            taskHeader2: '',
            taskInfoArrayA3: [],
            // c类department获取的部门编号
            departmentIdC: '',
            // C类显示
            tabShowC: false,
            TabShowIsssue: false,
            // B类department具体的部门名称
            departmentNameB: '',
            departmentNameB2: ''
        };
    },
    methods: {
        // 任务树折叠
        clickNodeA(index) {
            this.taskDataA[index].isShow = !this.taskDataA[index].isShow;
            this.$forceUpdate();
        },
        test(item) {
            if (item) {
                if (item.slice(0, -2) == this.departmentLabel) {
                    return true;
                } else {
                    return false;
                }
            }
        },
        showBIssueMethod(i) {
            console.log("aaa");
            this.taskDataB[i].isShow = !this.taskDataB[i].isShow
            console.log(this.taskDataB[i].isShow);
            
            this.departmentNameB = this.taskDataB[i].allocDeptId;
            
            this.childYearId = this.value;
            this.childYear = this.label;
            this.TabShowIsssue = true;
            this.tabShowBLevel2 = false;
            this.tabShowBLevel3 = false;
            this.tabBLast = false;
            this.tabALast = false;
            this.tabA3 = false;
            this.tabA = false;
            this.tabB_all = false;
            this.tabB_view = false;
            this.tabC = false;
            this.$forceUpdate()
        },
        reloadA3() {},
        // 根据id查询任务信息
        async searchTaskById(id) {
            await workOfYearTargetApi.getWorkNameOfYearTargetById(id).then((res) => {
                this.taskInfo = res.data;
                this.childYear = this.label;
                this.$forceUpdate();
                this.level1DialogVisible = true;
                this.showSingal = false;
                this.showMultiply = false;
                this.tabALast = false;
            });
        },
        // 点击年度目标任务A所有
        async clickA() {
            this.tabShowC = false;
            this.TabShowIsssue = false;
            this.tabShowBLevel2 = false;
            this.tabShowBLevel3 = false;
            this.typeOneShow = true;
            this.showMultiply = false;
            this.showSingal = false;
            this.tabALast = false;
            this.tabB_all = false;
            this.tabBLast = false;
            this.sideB = false;
            this.sideC = false;
            this.workInfo_view = true;
            this.allocatWork_view = true;
            this.issueWrok_view = true;
            this.tabShowC = false;

            await workOfYearTargetApi.getWorkOfYearTarget(this.value, 0).then((res) => {
                this.taskDataA = res.data;
                this.taskData = [];
                for (let i = 0; i < res.data.length; ++i) {
                    if (res.data[i].level == 0) {
                        this.taskData.push(res.data[i]);
                    }
                }
                this.taskDataA = this.toTree(this.taskDataA);
            });

            for (let i = 0; i < this.taskDataA.length; ++i) {
                let obj = {};
                if (this.taskDataA[i].children) {
                    for (let j = 0; j < this.taskDataA[i].children.length; ++j) {
                        let item = this.taskDataA[i].children[j].acceptDeptId;
                        obj[item] = obj[item] + 1 || 1;
                        let temp = obj[item] >= 10 ? obj[item] : '0' + obj[item];
                        this.taskDataA[i].children[j].acceptDeptId = this.taskDataA[i].children[j].acceptDeptId + temp;
                    }
                }
            }
            for (let z = 0; z < this.taskDataA.length; ++z) {
                if (this.taskDataA[z].children) {
                    for (let p = 0; p < this.taskDataA[z].children.length; ++p) {
                        if (this.taskDataA[z].children[p].children) {
                            this.taskDataA[z].children[p].children = this.unique(this.taskDataA[z].children[p].children, 'acceptDeptId');
                        }
                    }
                }
            }
            this.AllTaskDataA = this.taskDataA;
            if (this.departmentValue != '') {
                let tempDataAA = this.taskDataA;
                this.taskDataA = [];
                for (let i = 0; i < tempDataAA.length; ++i) {
                    if (this.departmentLabel == tempDataAA[i].acceptDeptId) {
                        this.taskDataA.push(tempDataAA[i]);
                        continue;
                    }
                    if (tempDataAA[i].children) {
                        for (let j = 0; j < tempDataAA[i].children.length; ++j) {
                            if (this.departmentLabel == tempDataAA[i].children[j].acceptDeptId.slice(0, -2)) {
                                this.taskDataA.push(tempDataAA[i]);
                                break;
                            }

                            if (tempDataAA[i].children[j].children) {
                                for (let k = 0; k < tempDataAA[i].children[j].children.length; ++k) {
                                    if (this.departmentLabel == tempDataAA[i].children[j].children[k].acceptDeptId) {
                                        this.taskDataA.push(tempDataAA[i]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            for (let i = 0; i < this.taskDataA.length; ++i) {
                this.taskDataA[i].isShow = false;
            }
            this.sideA = !this.sideA;
            this.$forceUpdate();
        },
        unique(arr, attrName) {
            const res = new Map();
            return arr.filter((a) => !res.has(a[attrName]) && res.set(a[attrName], 1));
        },
        // 点击年度目标任务B所有
        async clickB() {
            this.tabALast = false;
            this.showSingal = false;
            this.showMultiply = false;
            this.tabShowC = false;
            this.typeOneShow = false;
            this.sideA = false;
            
            this.sideC = false;
            this.workInfo_view = true;
            this.allocatWork_view = true;
            this.issueWrok_view = true;
            await workOfYearTargetApi.getWorkOfYearTarget(this.value, 1).then((res) => {
                this.taskDataB = res.data;
                this.taskDataB = this.toTree1(this.taskDataB);
                for (let w = 0; w < this.taskDataB.length; ++w) {
                    if (this.taskDataB[w].children) {
                        this.taskDataB[w].children = this.taskDataB[w].children.map((item, index) => {
                            return Object.assign({}, { acceptDeptId: item.acceptDeptId, level: item.level });
                        });
                        this.taskDataB[w].children = this.unique(this.taskDataB[w].children, 'acceptDeptId');
                    }
                }
                this.AllTaskDataB = this.taskDataB;

                if (this.departmentValue != '') {
                    let tempDataB = this.taskDataB;
                    this.taskDataB = [];
                    for (let i = 0; i < tempDataB.length; ++i) {
                        if (this.departmentLabel == tempDataB[i].acceptDeptId || this.departmentLabel == tempDataB[i].allocDeptId) {
                            this.taskDataB.push(tempDataB[i]);
                            continue;
                        }

                        for (let j = 0; j < tempDataB[i].children.length; ++j) {
                            if (this.departmentLabel == tempDataB[i].children[j].acceptDeptId) {
                                this.taskDataB.push(tempDataB[i]);
                            }
                        }
                    }
                }
                for (let i = 0; i < this.taskDataB.length; ++i) {
                    this.taskDataB[i].isShow = false;
                }
                this.sideB = !this.sideB;
                this.$forceUpdate();
            });
        },
        // 点击年度目标任务C所有
        async clickC() {
            this.typeOneShow = false;
            this.typeOneShow = false;
            this.TabShowIsssue = false;
            this.tabShowBLevel2 = false;
            this.tabShowBLevel3 = false;
            this.tabALast = false;
            this.showSingal = false;
            this.showMultiply = false;
            this.sideA = false;
            this.sideB = false;
            this.sideC = !this.sideC;
            this.workInfo_view = true;
            this.allocatWork_view = false;
            this.issueWrok_view = true;

            await workOfYearTargetApi.getWorkOfYearTarget(this.value, 2).then((res) => {
                this.taskDataC = res.data;
                this.taskDataC = this.unique(this.taskDataC, 'acceptDeptId');
            });
            this.AllTaskDataC = this.taskDataC;
            if (this.departmentValue != '') {
                let tempDataA = this.taskDataC;
                this.taskDataC = [];
                for (let i = 0; i < tempDataA.length; ++i) {
                    if (this.departmentLabel == tempDataA[i].acceptDeptId) {
                        this.taskDataC.push(tempDataA[i]);
                    }
                }
            }
        },
        // 获取具体的任务信息
        TaskInfoShow(i, type) {
            if (type == 'A') {
                this.taskInfo = this.taskDataA[i];
                this.childYear = this.label;
                this.showSingal = true;
                this.showMultiply = false;
                this.typeOneShow = false;
                this.tabALast = false;
            }
            if (type == 'B') {
                this.departmentNameB = this.taskDataB[i].allocDeptId;
                this.taskInfo = this.taskDataB[i];
                for (let j = 0; j < this.$store.state.department.department.length; ++j) {
                    if (this.taskInfo.acceptDeptId == this.$store.state.department.department[j].name) {
                        if (this.$store.state.department.department[j].type == 2) {
                            this.tabShowBLevel2IsDept = false;
                        } else {
                            this.tabShowBLevel2IsDept = true;
                        }
                    }
                }
                this.childYear = this.label;
                this.TabShowIsssue = false;
                this.tabShowBLevel3 = false;
                this.tabShowBLevel2 = true;
            }
            if (type == 'C') {
                this.tabShowC = true;
                // C类部门
                this.departmentNameB = this.taskDataC[i].acceptDeptId;
                let departmentName = this.taskDataC[i].acceptDeptId;
                for (let j = 0; j < this.$store.state.department.department.length; ++j) {
                    if (departmentName == this.$store.state.department.department[j].name) {
                        this.departmentIdC = this.$store.state.department.department[j].id;
                    }
                }

                this.childYearId = this.value;
                this.childYear = this.label;
                this.$forceUpdate();
            }
        },
        TaskInfoShowLevel2(i, j, type) {
            this.$forceUpdate();
            this.taskInfoArray = [];
            this.taskHeader = this.taskData[i].name;
            let departmentName = this.taskDataA[i].children[j].acceptDeptId.slice(0, -2);
            this.childYearId = this.value;
            this.childYear = this.label;
            for (let x = 0; x < this.$store.state.department.department.length; ++x) {
                if (departmentName == this.$store.state.department.department[x].name) {
                    if (this.$store.state.department.department[x].type == 2) {
                        this.isDept = false;
                    } else {
                        this.isDept = true;
                    }
                    break;
                }
            }
            let temp = this.taskDataA[i].children;
            for (let i = 0; i < temp.length; ++i) {
                if (temp[i].acceptDeptId.slice(0, -2) == departmentName) {
                    temp[i].isDept = this.isDept;
                    this.taskInfoArray.push(temp[i]);
                }
            }

            this.typeOneShow = false;
            this.showMultiply = true;
            this.showSingal = false;
            this.tabALast = false;
        },
        async TaskInfoShowB3(i, j) {
            this.TabShowIsssue = false;
            this.tabShowBLevel2 = false;
            this.typeOneShow = false;
            this.showSingal = false;
            this.showMultiply = false;
            this.typeOneShow = false;
            this.tabALast = false;
            this.tabShowBLevel3 = true;
            this.taskDataB3 = [];
            this.childYearId = this.value;
            this.childYear = this.label;
            let departmentName = this.taskDataB[i].children[j].acceptDeptId;
            let departmentId = this.taskDataB[i].acceptDeptId;
            this.departmentNameB = this.taskDataB[i].allocDeptId;
            this.departmentNameB2 = this.taskDataB[i].acceptDeptId;
            for (let z = 0; z < this.$store.state.department.department.length; ++z) {
                if (departmentId == this.$store.state.department.department[z].name) {
                    departmentId = this.$store.state.department.department[z].id;
                }
            }
            await workOfYearTargetApi.getTargetTwo(this.taskDataB[i].id, 1, departmentId).then((res) => {
                let temp = res.data;
                for (let i = 0; i < temp.length; ++i) {
                    if (temp[i].acceptDeptId == departmentName) {
                        this.taskDataB3.push(temp[i]);
                    }
                }
            });
        },
        async TaskInfoShowA3(i, j, k) {
            this.showSingal = false;
            this.showMultiply = false;
            this.typeOneShow = false;
            this.tabALast = true;
            this.childYearId = this.value;
            this.childYear = this.label;
            this.taskHeader = this.taskData[i].name;
            this.taskHeader2 = this.taskData[i].children[j].name;
            let departmentId;
            departmentId = this.taskData[i].children[j].acceptDeptId.slice(0, -2);
            let departmentName = this.taskData[i].children[j].children[k].acceptDeptId;
            for (let z = 0; z < this.$store.state.department.department.length; ++z) {
                if (departmentId == this.$store.state.department.department[z].name) {
                    departmentId = this.$store.state.department.department[z].id;
                }
            }
            await workOfYearTargetApi.getTargetTwo(this.taskData[i].children[j].id, 1, departmentId).then((res) => {
                this.taskInfoArrayA3 = [];
                let temp = res.data;
                for (let i = 0; i < temp.length; ++i) {
                    if (temp[i].acceptDeptId == departmentName) {
                        this.taskInfoArrayA3.push(temp[i]);
                    }
                }
            });
        },
        searchWorkOfTargetYear() {
            this.getLabel();
        },
        //——————————————————————————————————————————————————————————————————————————
        // 根据value 获取当前的label的值
        getLabel() {
            let obj = {};
            obj = this.yearTargetOptions.find((item) => {
                return item.value == this.value;
            });
            this.label = obj.label;
        },
        getDepartmentLabel() {
            let obj1 = {};
            obj1 = this.departmentOptions.find((item) => {
                return item.value == this.departmentValue;
            });
            this.departmentLabel = obj1.label;
        },
        //获取年份
        async getTargetYear() {
            await yearTargetApi.findAll().then((res) => {
                for (let i = 0; i < res.data.length; ++i) {
                    this.yearTargetOptions[i] = {
                        value: res.data[i].id,
                        label: res.data[i].name
                    };
                }
                this.value = this.yearTargetOptions[0].value;
                this.label = this.yearTargetOptions[0].label;
                // 强制刷新 解决有数据不渲染的问题

                this.$forceUpdate();
            });
        },
        // 获取部门信息
        getDepartments() {
            this.$store.dispatch('getDepartment');
            let obj1 = this.$store.state.department.department;
            for (let j = 0; j < obj1.length; ++j) {
                this.departmentOptions[j] = {
                    value: obj1[j].id,
                    label: obj1[j].name
                };
            }
            this.departmentOptions.unshift({
                value: '',
                label: '全部'
            });
            // 强制刷新 解决有数据不渲染的问题
            this.$forceUpdate();
        },
        toTree(param) {
            //没有父节点的数据
            let parents = param.filter((value) => value.level == 0);

            //有父节点的数据
            let children = param.filter(
                (value) => value.parentId !== 'undefined' && value.parentId != null && (value.level == 1 || value.level == 2)
            );
            //定义转换方法的具体实现
            let translator = (parents, children) => {
                //遍历父节点数据
                parents.forEach((parent) => {
                    //遍历子节点数据
                    children.forEach((current, index) => {
                        //此时找到父节点对应的一个子节点
                        if (current.parentId === parent.id) {
                            //对子节点数据进行深复制，这里只支持部分类型的数据深复制，对深复制不了解的童靴可以先去了解下深复制
                            let temp = JSON.parse(JSON.stringify(children));
                            //让当前子节点从temp中移除，temp作为新的子节点数据，这里是为了让递归时，子节点的遍历次数更少，如果父子关系的层级越多，越有利
                            temp.splice(index, 1);
                            //让当前子节点作为唯一的父节点，去递归查找其对应的子节点
                            translator([current], temp);
                            //把找到子节点放入父节点的children属性中
                            typeof parent.children !== 'undefined' ? parent.children.push(current) : (parent.children = [current]);
                        }
                    });
                });
            };
            //调用转换方法
            translator(parents, children);
            //返回最终的结果
            return parents;
        },
        toTree1(param) {
            //没有父节点的数据
            let parents = param.filter((value) => value.level == 1);

            //有父节点的数据
            let children = param.filter(
                (value) => value.parentId !== 'undefined' && value.parentId != null && (value.level == 1 || value.level == 2)
            );
            //定义转换方法的具体实现
            let translator = (parents, children) => {
                //遍历父节点数据
                parents.forEach((parent) => {
                    //遍历子节点数据
                    children.forEach((current, index) => {
                        //此时找到父节点对应的一个子节点
                        if (current.parentId === parent.id) {
                            //对子节点数据进行深复制，这里只支持部分类型的数据深复制，对深复制不了解的童靴可以先去了解下深复制
                            let temp = JSON.parse(JSON.stringify(children));
                            //让当前子节点从temp中移除，temp作为新的子节点数据，这里是为了让递归时，子节点的遍历次数更少，如果父子关系的层级越多，越有利
                            temp.splice(index, 1);
                            //让当前子节点作为唯一的父节点，去递归查找其对应的子节点
                            translator([current], temp);
                            //把找到子节点放入父节点的children属性中
                            typeof parent.children !== 'undefined' ? parent.children.push(current) : (parent.children = [current]);
                        }
                    });
                });
            };
            //调用转换方法
            translator(parents, children);
            //返回最终的结果
            return parents;
        }
    },
    created() {
        this.getTargetYear();
        this.getDepartments();
        this.$store.dispatch('getTeachers');
        // this.$store.dispatch('getDepartment')
    },
    watch: {
        departmentLabel() {
            this.test();
            if (this.departmentValue != '') {
                // C类
                let tempDataA = this.AllTaskDataC;
                this.taskDataC = [];
                for (let i = 0; i < tempDataA.length; ++i) {
                    if (this.departmentLabel == tempDataA[i].acceptDeptId) {
                        this.taskDataC.push(tempDataA[i]);
                    }
                }
                //B类
                let tempDataB = this.AllTaskDataB;
                this.taskDataB = [];
                for (let i = 0; i < tempDataB.length; ++i) {
                    if (this.departmentLabel == tempDataB[i].acceptDeptId || this.departmentLabel == tempDataB[i].allocDeptId) {
                        this.taskDataB.push(tempDataB[i]);
                        continue;
                    }
                    if (tempDataB[i].children) {
                        for (let j = 0; j < tempDataB[i].children.length; ++j) {
                            if (this.departmentLabel == tempDataB[i].children[j].acceptDeptId) {
                                this.taskDataB.push(tempDataB[i]);
                            }
                        }
                    }
                }
                // A类
                let tempDataAA = this.AllTaskDataA;
                this.taskDataA = [];
                for (let i = 0; i < tempDataAA.length; ++i) {
                    if (this.departmentLabel == tempDataAA[i].acceptDeptId) {
                        this.taskDataA.push(tempDataAA[i]);
                        continue;
                    }
                    if (tempDataAA[i].children) {
                        for (let j = 0; j < tempDataAA[i].children.length; ++j) {
                            if (this.departmentLabel == tempDataAA[i].children[j].acceptDeptId.slice(0, -2)) {
                                this.taskDataA.push(tempDataAA[i]);
                                break;
                            }

                            if (tempDataAA[i].children[j].children) {
                                for (let k = 0; k < tempDataAA[i].children[j].children.length; ++k) {
                                    if (this.departmentLabel == tempDataAA[i].children[j].children[k].acceptDeptId) {
                                        this.taskDataA.push(tempDataAA[i]);
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                this.taskDataC = this.AllTaskDataC;
                this.taskDataB = this.AllTaskDataB;
                this.taskDataA = this.AllTaskDataA;
            }
        }
    }
};
</script>

<style scoped>
.el-tree-style {
    padding: 0px 40px;
}
.el-tree-node__label {
    color: #606266;
}
/* .el-tag {
    float: right;
} */
div /deep/ .el-input.is-disabled .el-input__inner {
    color: #000;
}
.title {
    border: 1px #bcbcbc;
    width: 50%;
    margin: 0 auto;
}
.card {
    border-radius: 15px;
    width: 50%;
    margin: 0 auto;
}
.el-menu-item.is-active {
    color: #409eff;
}
.menu-buttom {
    padding-bottom: 20px;
}
.menu-click {
    cursor: pointer;
}
</style>